<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    /*
    前置知识点
    * */
    // 日期转时间戳
    let date1 = new Date('2022-9-5')
    let date2 = new Date('2022-9-6')
    // 获取日期的 年份
    let year1 = date1.getFullYear()
    let year2 = date2.getFullYear()
    console.log(year1,year2) // 2022 2022

    // 获取日期的 月份
    let month1 = date1.getMonth() + 1
    let month2 = date2.getMonth() + 1
    console.log(month1,month2) // 9 9

    // 获取日期的 日期
    let day1 = date1.getDate()
    let day2 = date2.getDate()
    console.log(day1,day2) // 5 6

    // 获取当天的时间戳
    let time1 = date1.getTime()
    let time2 = date2.getTime()
    console.log(time2-time1) // 86400000  一天多少毫秒

    // 求两个日期之间的有效时间
    function validTime(day1,day2){
        let res = [day1]
        let date1 = new Date(day1)
        let date2 = new Date(day2)
        let time1 = date1.getTime()
        let time2 = date2.getTime()
        // 一天的毫秒数
        let count = 0
        let oneDayTime = 24*60*60*1000
        while( ((time2-time1) - count*oneDayTime ) > 0 ){
            count++
            let item = new Date((time1+count*oneDayTime))
            res.push( item.getFullYear() + '-' + (item.getMonth() + 1) + '-' + item.getDate() )
        }
        return res
    }
    console.log(validTime('2022-9-10','2022-9-15'))
</script>
</body>
</html>
